/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.gtm.congestion;

import bgu.ppm.gtm.base.ImmutableStrategy;
import bgu.ppm.gtm.base.PlayerValueFunction;
import bgu.ppm.gtm.base.StrategyProfile;

/**
 *
 * @author User
 */
public class FeedbackCongestionGameModel extends CongestionGameModel {

    @Override
    protected void _initialize() {
        super._initialize();

        setCostFunction(new PlayerValueFunction() {
            @Override
            public double calculate(int player, ImmutableStrategy strategy, StrategyProfile profile) {
                CongestionStrategyProfile cprofile = (CongestionStrategyProfile) profile;
                double cost = 0;
                for (int i = 0; i < getNumberOfResources(); i++) {
                    int congestion = cprofile.getCongestionForResourceWithoutPlayer(i, player) + (strategy.get(i) + 1) / 2;

                    if (congestion > 0) {
                        cost += strategy.get(i) * getResourcesCostFunction().cost(i, congestion);
                    }
                }

                return cost;
            }
        });
    }
}
